package com.thiswhyme.mq.kafka.producer.config;

import com.thiswhyme.mq.kafka.common.consts.TopicNameDefinition;
import org.apache.kafka.clients.admin.NewTopic;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @description: Kafka配置
 * @author: thiswhyme
 * @date: 2021/4/21
 */
@Configuration
public class KafkaConfig {

    /**
     * 创建一个名为TopicNameDefinition.COMMON_TOPIC的Topic并设置分区数为8，分区副本数为1
     * 如果要修改分区数，只需修改配置值重启项目即可，修改分区数并不会导致数据的丢失，但是分区数只能增大不能减小
     */
    @Bean
    public NewTopic initialTopic() {
        return new NewTopic(TopicNameDefinition.COMMON_TOPIC,1, (short) 1 );
    }

    @Bean
    public NewTopic initialTopic2() {
        return new NewTopic(TopicNameDefinition.COMMON_TOPIC2,1, (short) 1 );
    }

    @Bean
    public NewTopic initialTopic3() {
        return new NewTopic(TopicNameDefinition.FILTER_TOPIC,1, (short) 1 );
    }

    @Bean
    public NewTopic initialTopic4() {
        return new NewTopic(TopicNameDefinition.RESEND_TOPIC,1, (short) 1 );
    }

    @Bean
    public NewTopic initialTopic5() {
        return new NewTopic(TopicNameDefinition.TIMING_TOPIC,1, (short) 1 );
    }
}
